#pragma once

#ifndef _CTRADEHANDLER_H_
#define _CTRADEHANDLER_H_

#include "CSemaphore.h"
#include "CTrade.h"
#include "CItem.h"
#include "CChar.h"

class CTradeHandler {
public:
	//trade list semaphore
	static CSemaphore * tradeListSemaphore;

	static void initialize();

	static void createTrade(CChar * schar1, CChar * schar2);

	// Get trade from trade list
	static CTrade * getTrade(int tradeId);

	// Add item to trade
	static void addItemTrade(unsigned short itemID, unsigned long quantity, unsigned char invSlotID, unsigned char tradeSlotID, CChar * schar1);

	// Remove item from trade
	static void removeItemTrade(unsigned char tradeSlotID, CChar * schar1);

	// A character has accepted trade
	static void tradeAccepted(CTrade * trade, CChar * schar, bool accepted);

	// Complete the trade.
	static void completeTrade(int tradeId);

	// Delete trade when cancelled / complete
	static void deleteTrade(int tradeId);

	// Do trade action from character
	static void tradeAction(CChar * schar1, unsigned long action);

	//List for all trades on server
	static std::vector<CTrade*> tradeList;

	//Waits until the trade list is free
	static void waitTradeList(void);

	//Waits until the trade is free
	static void exitTradeList(void);

	//Move items over.  Only called from completeTrade
	static void doTrade(CChar * schar1, CChar * schar2, CTradeContainer * trade);

	CTradeHandler();
	~CTradeHandler();
};

#endif